<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>register</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <!--    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"-->
    <!--          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"/>-->
    <!--    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>-->
    <link rel="stylesheet" th:href="@{/bootstrap.min.css}" />
    <script th:src="@{/vue.js}"></script>
</head>
<body>

<div th:insert="publicHeader"/>
<script th:src="@{/publicHeader.js}"></script>



<div class="container-fluid" id="app" style="margin-top: 180px;margin-bottom: 100px">

    <div class="container">

        <div class="row">
            <a href="/login.html">已有账号?立即去登录</a>
            <div class="col-md-4 col-md-offset-4" style="border: 1px solid #cccccc ;border-radius: 5px;margin-top: 10px">
                <form >
                    <div class="form-group">
                        <label for="account" >用户名:</label>
                        <input type="text" v-model="registerFrom.username" name="username" class="form-control" id="account" placeholder="请输入用户名">
                    </div>
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" v-model="registerFrom.password" name="password" class="form-control" id="password" placeholder="请输入密码">
                    </div>
                    <div class="form-group">
                        <label for="repass">确认密码:</label>
                        <input type="password" v-model="registerFrom.repass" name="repass" class="form-control" id="repass" placeholder="请输入确认密码">
                    </div>

                    <button type="submit" @click.prevent="toReg" class="btn btn-success">注册</button>
                </form>
            </div>
        </div>

    </div>

</div>

<script>

    console.log(".........register...........")

    let register = new Vue({
        el: "#app"
        ,
        data: {

            registerFrom:{
                username:'',
                password:'',
                repass:''
            }
        }
        ,
        methods: {

            toReg(){
                //1.搜集表单数据
                console.log(this.registerFrom)

                //做一些数据校验什么的.......

                //2.访问后端接口,根据访问结果做对应处理.
                // 成功: 提示并跳转到登录页
                // 失败: 提示错误信息
                $.post("/user/register",this.registerFrom,function (data) {
                    if (data=='ok'){
                        //注册成功,提示并跳转到登录页
                        alert("注册成功,立即前往登录页")
                        location.href="/login.html"
                    }else {
                        //注册失败
                        alert(data)
                    }
                })

            }

        }
        ,
        created(){

        }

    });


</script>


<div th:insert="publicFooter"/>
<script th:src="@{/publicFooter.js}"></script>


</body>
</html>